package com.guys8.cemsbackend.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.guys8.cemsbackend.entity.Account;
import com.guys8.cemsbackend.mapper.ClassUserMapper;
import com.guys8.cemsbackend.entity.ClassUser;
import com.guys8.cemsbackend.service.ClassUserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (ClassUser)表服务实现类
 *
 * @author breeze
 * @since 2022-08-24 16:53:22
 */
@Service("classUserService")
public class ClassUserServiceImpl extends MppServiceImpl<ClassUserMapper, ClassUser> implements ClassUserService {

    public ClassUser getbyuser_class(Integer userid,Integer classid){
        Map<String,Object> accountMap = new HashMap<>();
        accountMap.put("class_id",classid);
        accountMap.put("user_id",userid);
        List<ClassUser> classusers = this.listByMap(accountMap);
        if(classusers.size()<1)
            return null;
        ClassUser cuser = classusers.get(0);
        return cuser;
    }

    public boolean deletebyuser_class(Integer userid,Integer classid){
        Map<String,Object> accountMap = new HashMap<>();
        accountMap.put("class_id",classid);
        accountMap.put("user_id",userid);
        return this.removeByMap(accountMap);
    }

    public List<ClassUser> getstudentinclass(Integer classid){
        Map<String,Object> accountMap = new HashMap<>();
        accountMap.put("class_id",classid);
        accountMap.put("user_type",0);
        accountMap.put("audit_state",1);
        return this.listByMap(accountMap);
    }

    public ClassUser getteacherinclass(Integer classid){
        Map<String,Object> accountMap = new HashMap<>();
        accountMap.put("class_id",classid);
        accountMap.put("user_type",1);
        accountMap.put("audit_state",1);
        return this.listByMap(accountMap).get(0);
    }

    public List<ClassUser> getstudentwaitinclass(Integer classid){
        Map<String,Object> accountMap = new HashMap<>();
        accountMap.put("class_id",classid);
        accountMap.put("user_type",0);
        accountMap.put("audit_state",0);
        return this.listByMap(accountMap);
    }

    public List<ClassUser> getClassesbystudent(Integer userid){
        Map<String,Object> accountMap = new HashMap<>();
        accountMap.put("user_id",userid);
        accountMap.put("audit_state",1);
        return this.listByMap(accountMap);
    }

    public List<ClassUser> getClassesbyteacher(Integer userid){
        Map<String,Object> accountMap = new HashMap<>();
        accountMap.put("user_id",userid);
        accountMap.put("user_type",1);
        accountMap.put("audit_state",1);
        return this.listByMap(accountMap);
    }

    public void deletebyclass(Integer classId) {
        Map<String,Object> accountMap = new HashMap<>();
        accountMap.put("class_id",classId);
        this.removeByMap(accountMap);
    }
}

